package com.scpii.universal.struts.manage;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.doone.comm.paginaction.Pagination;
import com.scpii.universal.action.BaseAction;
import com.scpii.universal.constant.GenericConstants;
import com.scpii.universal.dto.FeedBackDto;
import com.scpii.universal.hibernate.entity.FeedbackTab;
import com.scpii.universal.service.FeedBackManageService;
import com.scpii.universal.service.FeedbackService;

@Controller
@Scope("prototype")
public class FeedBackManageAction extends BaseAction {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = -5355581628553658685L;

	@Resource
	private FeedBackManageService feedBackManageService;
	@Resource
	private FeedbackService feedbackService;
	// 最初的留言回复list
	List<FeedBackDto> rootFeedList;
	// 留言id
	private Integer intFeedbackId;
	//新增的留言内容
	private String content;
	// 当前记录的留言用户信息ID
	private Long intUserId;
	// 查询条件
	private FeedBackDto condition;
	// 分页信息
	private Pagination page = new Pagination();
	private Integer intFeedbackType;

	
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Long getIntUserId() {
		return intUserId;
	}

	public void setIntUserId(Long intUserId) {
		this.intUserId = intUserId;
	}

	public void setIntUserId(String intUserId) {
		if (intUserId != null && !"".equals(intUserId)) {
			this.intUserId = Long.parseLong(intUserId);
		} else {
			this.intUserId = null;
		}
	}

	public Integer getIntFeedbackId() {
		return intFeedbackId;
	}

	public void setIntFeedbackId(Integer intFeedbackId) {
		this.intFeedbackId = intFeedbackId;
	}

	public void setIntFeedbackId(String intFeedbackId) {
		if (intFeedbackId != null && !"".equals(intFeedbackId)) {
			this.intFeedbackId = Integer.parseInt(intFeedbackId);
		} else {
			this.intFeedbackId = null;
		}
	}

	public FeedBackDto getCondition() {
		return condition;
	}

	public void setCondition(FeedBackDto condition) {
		this.condition = condition;
	}

	public Pagination getPage() {
		return page;
	}

	public void setPage(Pagination page) {
		this.page = page;
	}

	public List<FeedBackDto> getRootFeedList() {
		return rootFeedList;
	}

	public void setRootFeedList(List<FeedBackDto> rootFeedList) {
		this.rootFeedList = rootFeedList;
	}

	public Integer getIntFeedbackType() {
		return intFeedbackType;
	}

	public void setIntFeedbackType(Integer intFeedbackType) {
		this.intFeedbackType = intFeedbackType;
	}

	/**
	 * 
	 * @return
	 * @author zhangqiaing 2012-7-20上午10:21:38
	 */
	public String getRootFeedInfo() {
		if (condition == null) {
			condition = new FeedBackDto();
		}
		// 设置appid
		condition.setIntAppId(getUserInfo().getAppId());

		// 判断第一次进入分页信息
		if (getSelectPerPage("page") == -1) {
			page.setPageRecord(GenericConstants.PAGE_NO);
		} else {
			page.setPageRecord(getSelectPerPage("page"));
		}
		// 判断是否是第一次查询
		if (getQueryFlag("page") == -1) {
			page.setTotalRecord(feedBackManageService
					.getCountByCondition(condition));
		} else {
			page.setTotalRecord(getQueryFlag("page"));
		}
		setPageParameters(page, "page");
		rootFeedList = feedBackManageService.geFeedBackList(condition,
				page.getCurrentPage(), page.getPageRecord());

		return SUCCESS;
	}

	/**
	 * 获取留言的详细信息
	 * 
	 * @return
	 * @author zhangqiaing 2012-7-20上午10:21:54
	 */
	public String getFeedBackDetailInfo() {
		// 用户留言信息
		List<FeedBackDto> contetnList = feedBackManageService
				.getFeedBackDetailInfo(intFeedbackId, intUserId, getUserInfo()
						.getAppId());
		// 管理员留言信息
		rootFeedList = feedBackManageService.getContentDetailInfo(contetnList);
		return SUCCESS;
	}
	
	/**
	 * 删除留言信息
	 * @return
	 */
	public String delRootFeedInfo() {
		feedBackManageService.delFeedBackInfo(intFeedbackId);
		return null;
	}

	/**
	 * 
	 * @return
	 * @author zhangqiaing 2012-7-20下午03:56:32
	 */
	public String addContent() {
		
		
		FeedbackTab tab=new FeedbackTab();
		tab.setIntAdminId((long)getUserInfo().getIntUserId());
		tab.setIntAppId(getUserInfo().getAppId());
		tab.setIntDeleteSign(GenericConstants.DELETE_SIGN_EXIST);
		tab.setIntParentFeedbackId(intFeedbackId);
//		tab.setIntUserId(intUserId);
		tab.setIntFeedbackType(intFeedbackType);
		tab.setIntReplyStatus(0);
		SimpleDateFormat sdf=new SimpleDateFormat(GenericConstants.DATE_FORMAT);
		String date = sdf.format(new Date());
		tab.setDatFeedbackDatetime(date);
		tab.setVarFeedbackContent(content);
		tab.setDatUpdateDatetime(date);
		feedbackService.save(tab);
		return SUCCESS;

	}
}
